package com.ruoyi.business.config;

import com.ruoyi.business.interceptor.MqttPushClient;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@ConfigurationProperties(prefix = "spring.mqtt")
@Data
public class MqttConfig {
    private static final Logger logger = LoggerFactory.getLogger(MqttConfig.class);

    @Autowired
    private MqttPushClient mqttPushClient;
    /**
     * 用户名
     */
    private String username;
    /**
     * 密码
     */
    private String password;
    /**
     * 连接地址
     */
    private String hostUrl;
    /**
     * 消费客户端Id
     */
    private String inClientId;
    /**
     * 生产客户端ID
     */
    private String outClientId;
    /**
     * 持久会话（true-非持久，false-持久会话）
     */
    private Boolean clearSession;
    /**
     * 超时时间
     */
    private int timeout;
    /**
     * 保持连接数
     */
    private int keepalive;
    /**
     * mqtt功能使能
     */
    private boolean enabled;
    /**
     * 遗嘱主题
     */
    private String willTopic;
    /**
     * 遗嘱Qos
     */
    private Integer willQos;
    /**
     * 遗嘱保留标志
     */
    private Boolean willRetained;
    /**
     * 遗嘱消息
     */
    private String willPayload;
    /**
     * 自动重连
     */
    private Boolean autoReconnect;
    /**
     * 主题集合
     */
    private List<String> topicList;

    private String topicSend;

    //注入spring
    @Bean
    public MqttPushClient getMqttPushClient() {
        if (enabled) {
            mqttPushClient.connect();
        }
//        MqttPushClient mqttPushClient = new MqttPushClient();
        return mqttPushClient;
    }

    public String getServerStateTopic() {
        return "xgscpc/seating/server/state";
    }
}

